{
	var rebind=getURLParameter("rebind");
	if(rebind!=null&&typeof(rebind)!='undefined'&&eval(rebind)){
		bindSinaSNS();
	}else{
		var state=getURLParameter("state");
		if(state!=null&&typeof(state)!='undefined'&&state=='sina'){
			var code=getURLParameter("code");
			jQ.ajax({
				type: "POST",
				url:"userAjax!userBindSinacode.action",
				data:{
					code:code
				},
				async:false,
				success:function(data){
					if(data.result){
						var url=data.trun2url;
						if(url!=null&&url.length>0){
							window.location.href=url;
						}else
							window.location.href="./userinfo.html";
					}else{
						alert(data.errormsg);
						window.location.href="./userinfo.html";
					}
				}
			});
		}
	}
}

function getURLParameter(name){
    var paramStr=location.search;
    if(paramStr.length==0)return null;
    if(paramStr.charAt(0)!='?')return null;
    paramStr=unescape(paramStr);
    paramStr=paramStr.substring(1);
    if(paramStr.length==0)return null;
    var params=paramStr.split('&');
    var p = null;
    for(var i=0;i<params.length;i++){
        if(params[i].indexOf(name) >= 0){
            p = params[i].split('=');
            if(p[0]==jQ.trim(name))
            	p = p[1];
        }
    }
    return p;
}

var dataObj;
jQ(function(){
	loadUserInfo();
	
	jQ("#viewopt").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:false,
		height:200,
		buttons: {
			
			"确定": function() {
				var opt=jQ("#viewopt");
				var triggerfun=opt.data("function");
				opt.trigger(triggerfun);
				opt.removeData("function");
				jQ("#viewopt_p").hide();
				jQ("#viewopt_img").show();
				//activeBtnOnDialog("viewopt",false);
				//jQ(this).dialog('close');
			},
			"取消": function() {
				var viewopt=jQ("#viewopt");
				var triggerfun=jQ("#viewopt").data("function");
				viewopt.unbind(triggerfun);
				viewopt.find("input.eventid").val("");
				viewopt.removeData("function");
				jQ(this).dialog('close');
			}
		},
		close: function() {
			jQ("#viewopt_p").show();
			jQ("#viewopt_img").hide();
		},
		open:function(){
		}
	});
});



function toedit(obj){
	//设置名称
	var name=jQ("#userinfo_name").data("name");
	jQ("#userinfo_name").empty().append("<input type=\"text\" value=\""+name+"\"/>");
	//设置性别
	var sex=jQ("#userinfo_sex").data("sex");
	var sexhtml="";
	if(sex==1){
		sexhtml="<input type=\"radio\" style='width:auto;' name=\"sex\" value=\"1\" checked=\"checked\"/>男";
		sexhtml+="<input type=\"radio\" style='width:auto;' name=\"sex\" value=\"2\" />女";
	}else{
		sexhtml="<input type=\"radio\" style='width:auto;' name=\"sex\" value=\"1\" />男";
		sexhtml+="<input type=\"radio\" style='width:auto;' name=\"sex\" value=\"2\" checked=\"checked\"/>女";
	}
	jQ("#userinfo_sex").empty().append(sexhtml);
	//设置生日
	var birthlong=jQ("#userinfo_birth").data("birthlong");
	jQ("#userinfo_birth").empty().append("<input type=\"text\" onfocus='this.blur();'/>");
	jQ("#userinfo_birth").find("input").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		detailtime:false,
		beforeShow: function(i,e){  
			var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
			e.dpDiv.css('z-index', z);
			e.dpDiv.css('font', "14px \"Trebuchet MS\", sans-serif");
		},
		onClose: function(dateText,inst) {
			
		}
	});
	if(birthlong>0){
		var tmpdate=new Date();
		tmpdate.setTime(birthlong);
		jQ("#userinfo_birth").find("input").datepicker("setDate",tmpdate);
	}
	//设置qq,msn,blog
	var qq=jQ("#userinfo_qq").data("qq");
	jQ("#userinfo_qq").empty().append("<input type=\"text\" value=\""+qq+"\"/>");
	var msn=jQ("#userinfo_msn").data("msn");
	jQ("#userinfo_msn").empty().append("<input type=\"text\" value=\""+msn+"\"/>");
	var blog=jQ("#userinfo_blog").data("blog");
	jQ("#userinfo_blog").empty().append("<input type=\"text\" value=\""+blog+"\"/>");
	//设置address
	var sufaddress=jQ("#userinfo_living").data("sufaddress");
	var addresscode=jQ("#userinfo_living").data("addresscode");
	jQ("#userinfo_living").empty().append("<div id='preaddressdiv'></div><div><input id='sufaddress' type='text' value='"+sufaddress+"'>")
	var pid=0,cid=0,did=0;
	if(addresscode.length>0){
		if(addresscode.indexOf("_")>0){
			var temparr=addresscode.split("_");
			pid=eval(temparr[0]);
			cid=eval(temparr[1]);
			if(temparr.length>2){
				did=eval(temparr[2]);
			}
		}else{
			pid=eval(addresscode);
		}
	}
	var html="";
	jQ.ajax({
		type: "POST",
		url: "userAjax!loadAllProvinces.action",
		success:function(data){
			if(data.result){
				
				html+="<select>";
				if(pid==0){
					html+="<option value='0' type='0'>";
					html+="请选择";
					html+="</option>";
				}
				var pname,ptype;
				for(var i=0;i<data.provinces.length;i++){
					var province=data.provinces[i];
					var provinceid=province.id;
					var name=province.name;
					var type=province.type;
					if(pid==provinceid){
						pname=name;
						ptype=type;
						html+="<option value='"+provinceid+"' type='"+type+"' selected='selected'>";
					}else{
						html+="<option value='"+provinceid+"' type='"+type+"'>";
					}
					html+=name;
					html+="</option>";
				}
				html+="</select>";
				if(pid==0){
					html+="<select>";
					html+="<option value='0' type='0'>";
					html+="请选择";	
					html+="</option>";
					html+="<select>";
					html+="<select>";
					html+="<option value='0' type='0'>";
					html+="请选择";	
					html+="</option>";
					html+="<select>";
					jQ("#preaddressdiv").append(html);
					initAreaSelect();
					return;
				}
				if(cid==0){
					if(ptype==0){
						jQ.ajax({
							type: "POST",
							url: "userAjax!loadCityByProvinceid.action",
							data:{
								provinceid:pid,
								type:0
							},
							success:function(data){
								if(data.result){
									
									html+="<select>";
									html+="<option value='0' type='0'>";
									html+="请选择";	
									html+="</option>";
									for(var i=0;i<data.cities.length;i++){
										var city=data.cities[i];
										var cityid=city.id;
										var name=city.name;
										var type=city.type;
										if(cityid==cid){
											html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"' selected='selected'>";
										}else{
											html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"'>";
										}
										html+=name;
										html+="</option>";
									}
									html+="</select>";

									html+="<select>";
									html+="<option value='0' type='0'>";
									html+="请选择";
									html+="</option>";
									html+="</select>";
									jQ("#preaddressdiv").append(html);
									initAreaSelect();
									return;
								}
							}
						});
					}else{
						
						html+="<select>";
						html+="<option value='0'>";
						html+=pname;
						html+="</option>";
						html+="</select>";
						jQ.ajax({
							type: "POST",
							url: "userAjax!loadDistrict.action",
							data:{
								cityid:0,
								provinceid:pid
							},
							success:function(data){
								if(data.result){
									html+="<select>";
									if(did==0){
										html+="<option value='0' type='0'>";
										html+="请选择";
										html+="</option>";
									}
									for(var i=0;i<data.districts.length;i++){
										var districts=data.districts[i];
										var districtid=districts.id;
										var name=districts.name;
										var type=districts.type;
										if(districtid==did){
											html+="<option value='"+districtid+"' type='"+type+"' selected='selected'>";
										}else
											html+="<option value='"+districtid+"' type='"+type+"'>";
										html+=name;
										html+="</option>";
									}
									html+="</select>";
									jQ("#preaddressdiv").append(html);
									initAreaSelect();
									return;
								}else{
									alert("数据出错");
								}
							}
						});
					}
				}else{
					jQ.ajax({
						type: "POST",
						url: "userAjax!loadCityByProvinceid.action",
						data:{
							provinceid:pid,
							type:0
						},
						success:function(data){
							if(data.result){
								
								html+="<select>";
								if(cid==0){
									html+="<option value='0' type='0'>";
									html+="请选择";	
									html+="</option>";
								}
								for(var i=0;i<data.cities.length;i++){
									var city=data.cities[i];
									var cityid=city.id;
									var name=city.name;
									var type=city.type;
									if(cityid==cid){
										html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"' selected='selected'>";
									}else{
										html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"'>";
									}
									html+=name;
									html+="</option>";
								}
								html+="</select>";
								
								jQ.ajax({
									type: "POST",
									url: "userAjax!loadDistrict.action",
									data:{
										cityid:cid,
										provinceid:pid
									},
									success:function(data){
										if(data.result){
											
											html+="<select>";
											if(did==0){
												html+="<option value='0' type='0'>";
												html+="请选择";
												html+="</option>";
											}
											for(var i=0;i<data.districts.length;i++){
												var districts=data.districts[i];
												var districtid=districts.id;
												var name=districts.name;
												var type=districts.type;
												if(districtid==did){
													html+="<option value='"+districtid+"' type='"+type+"' selected='selected'>";
												}else{
													html+="<option value='"+districtid+"' type='"+type+"'>";
												}
												html+=name;
												html+="</option>";
											}
											html+="</select>";
											jQ("#preaddressdiv").append(html);
											initAreaSelect();
											return;
										}else{
											alert("数据出错");
										}
									}
								});
							}else{
								alert("数据出错");
							}
						}
					});
				}
			}else{
				alert("数据出错");
			}
		}
	});
	var opthtml="";
	opthtml+="<li class=\"separate opt\">";
	opthtml+="<span class=\"errormsg\"></span>";
	opthtml+="<a id='userinfo_cancel'>取消</a>";
	opthtml+="<a id='userinfo_confirm'>确定</a>";
	opthtml+="</li>"
	jQ("#userinfolist").append(opthtml);
	jQ("#userinfo_cancel").bind("click",exituserinfoedit);
	jQ("#userinfo_confirm").bind("click",confirmuserinfoedit);
	jQ(obj).hide();
//	jQ("div.edit").show();
}

function initAreaSelect(){
	jQ("#preaddressdiv select").eq(0).change(onProvincesSelect);
	jQ("#preaddressdiv select").eq(1).change(onCitesSelect);
}

function onProvincesSelect(){
	var cityselect=jQ("#preaddressdiv select").eq(1);
	var districtselect=jQ("#preaddressdiv select").eq(2);
	var id=eval(jQ(this).val());
	var type=eval(jQ(this).find("option:selected").attr("type"));
	if(id==0){
		return;
	}else{
		if(type==-1){
			var name=jQ(this).find("option:selected").text();
			cityselect.empty().append("<option type='-1' id='"+id+"'>"+name+"</option>");
			jQ.ajax({
				type: "POST",
				url: "userAjax!loadDistrict.action",
				data:{
					cityid:0,
					provinceid:id
				},
				success:function(data){
					if(data.result){
						districtselect.empty();
						var html="";
						html+="<option value='0' type='0'>";
						html+="请选择";
						html+="</option>";
						for(var i=0;i<data.districts.length;i++){
							var districts=data.districts[i];
							var id=districts.id;
							var name=districts.name;
							var type=districts.type;
							html+="<option value='"+id+"' type='"+type+"'>";
							html+=name;
							html+="</option>";
						}
						districtselect.append(html);
					}else{
						alert("数据出错");
					}
				}
			});
			return;
		}else{
			jQ.ajax({
				type: "POST",
				url: "userAjax!loadCityByProvinceid.action",
				data:{
					provinceid:id,
					type:type
				},
				success:function(data){
					if(data.result){
						cityselect.empty();
						var html="";
						html+="<option value='0' type='0'>";
						html+="请选择";
						html+="</option>";
						for(var i=0;i<data.cities.length;i++){
							var city=data.cities[i];
							var cityid=city.id;
							var name=city.name;
							var type=city.type;
							html+="<option value='"+cityid+"' pid='"+id+"' type='"+type+"'>";
							html+=name;
							html+="</option>";
						}
						cityselect.append(html);
						cityselect.change(onCitesSelect);
					}else{
						alert("数据出错");
					}
				}
			});
		}
	}

}

function onCitesSelect(){
	var id=eval(jQ(this).val()); //cityid
	var pid=eval(jQ(this).find("option:selected").attr("pid"));
	var districtselect=jQ("#preaddressdiv select").eq(2);
	jQ.ajax({
		type: "POST",
		url: "userAjax!loadDistrict.action",
		data:{
			cityid:id,
			provinceid:pid
		},
		success:function(data){
			if(data.result){
				districtselect.empty();
				var html="";
				html+="<option value='0' type='0'>";
				html+="请选择";
				html+="</option>";
				for(var i=0;i<data.districts.length;i++){
					var districts=data.districts[i];
					var id=districts.id;
					var name=districts.name;
					var type=districts.type;
					html+="<option value='"+id+"' type='"+type+"'>";
					html+=name;
					html+="</option>";
				}
				districtselect.append(html);
			}else{
				alert("数据出错");
			}
		}
	});
}

function exituserinfoedit(){
	var name=jQ("#userinfo_name").data("name");
	jQ("#userinfo_name").empty().append(name);
	var sex=jQ("#userinfo_sex").data("sex");
	jQ("#userinfo_sex").empty().append(sex==1?"男":"女");
	var birth=jQ("#userinfo_birth").data("birth");
	jQ("#userinfo_birth").empty().append(birth);
	var qq=jQ("#userinfo_qq").data("qq");
	jQ("#userinfo_qq").empty().append(qq);
	var msn=jQ("#userinfo_msn").data("msn");
	jQ("#userinfo_msn").empty().append(msn);
	var blog=jQ("#userinfo_blog").data("blog");
	jQ("#userinfo_blog").empty().append(blog);
	var address=jQ("#userinfo_living").data("address");
	jQ("#userinfo_living").empty().append(address);
	jQ("#userinfolist li.opt").remove();
	jQ("#userinfo_editbtn").show();
}

function confirmuserinfoedit(){
	jQ("#userinfo_confirm").unbind("click");
	var name=jQ("#userinfo_name").find("input").val();
	var errormsgzone=jQ("#userinfolist li.opt span.errormsg");
	var nameRegEx = /^[\u4e00-\u9fa5_a-zA-Z0-9-]{2,20}$/;// 姓名 2-20个
	if(!nameRegEx.test(name)){
		errormsgzone.empty().append("姓名由2-20个字符中文、数字、英文、下划线、中杠线组成");
		return;
	}
	var sex=jQ("#userinfo_sex").find("input:checked").val();
	var birthdate=jQ("#userinfo_birth").find("input").datepicker("getDate");
	var birthlong=birthdate.getTime();
	var qq=jQ("#userinfo_qq").find("input").val();
	var msn=jQ("#userinfo_msn").find("input").val();
	var blog=jQ("#userinfo_blog").find("input").val();
	if(blog.length>0){
		if(!isURL(blog)){
			errormsgzone.empty().append("请输入正确的网址URL");
			return;
		}
	}
	var pre_address=getPreAddress();
	var suf_address=jQ.trim(jQ("#sufaddress").val());
	var address;
	if(pre_address=='0'&&suf_address.length<=0){
		address="";
	}else{
		address=pre_address+":"+suf_address;
	}
	if(pre_address!='0'&&suf_address.length<=0){
		errormsgzone.empty().append("请输入具体地址");
		return;
	}else if(suf_address.length>100){
		errormsgzone.empty().append("居住地地址不能超过100字");
		return;
	}
	jQ.ajax({
		type:"POST",
		url:"controlAjax!saveUserInfo.action",
		data:{
			nameInput:name,
			sex:sex,
			birthlong:birthlong,
			qqInput:qq,
			msnInput:msn,
			livingInput:address,
			blogInput:blog
		},
		success:function(data){
			if(data.result){
				jQ("#userinfo_name").data("name",name);
				jQ("#userinfo_name").empty().append(name);
				jQ("#userinfo_sex").data("sex",sex);
				jQ("#userinfo_sex").empty().append(sex==1?"男":"女");
				jQ("#userinfo_birth").data("birth",formateBirthTime(birthlong));
				jQ("#userinfo_birth").data("birthlong",birthlong);
				jQ("#userinfo_birth").empty().append(formateBirthTime(birthlong));
				jQ("#userinfo_qq").data("qq",qq);
				jQ("#userinfo_qq").empty().append(qq);
				jQ("#userinfo_msn").data("msn",msn);
				jQ("#userinfo_msn").empty().append(msn);
				jQ("#userinfo_blog").data("blog",blog);
				jQ("#userinfo_blog").empty().append(blog);
				var preaddtxt=getPreAddressText();
				jQ("#userinfo_living").empty().append(jQ.trim(preaddtxt+suf_address));
				jQ("#userinfo_living").data("sufaddress",suf_address);
				jQ("#userinfo_living").data("address",jQ.trim(preaddtxt+suf_address));
				jQ("#userinfo_living").data("addresscode",pre_address);
				jQ("#userinfolist li.opt").remove();
				jQ("#userinfo_editbtn").show();
			}else{
				jQ("#userinfo_confirm").bind("click",confirmuserinfoedit);
				errormsgzone.empty().append(data.errormsg);
				return;
			}
		}
	});
}
function getPreAddressText(){
	var pselect=jQ("#preaddressdiv select").eq(0);
	var cselect=jQ("#preaddressdiv select").eq(1);
	var dselect=jQ("#preaddressdiv select").eq(2);
	var pval=eval(pselect.val());
	if(pval==0){
		return "";
	}else{
		var ptxt=pselect.find("option:selected").text();
		var ptype=eval(pselect.find("option:selected").attr("type"));
		if(ptype==-1){
			var cval="0";
			var dval=eval(dselect.val());
			if(dval==0){
				return ""+ptxt;
			}else{
				return ptxt+" "+dselect.find("option:selected").text();
			}
		}else{
			var cval=eval(cselect.val());
			if(cval==0){
				return ""+ptxt;
			}else{
				var dval=eval(dselect.val());
				if(dval==0){
					return ptxt+" "+cselect.find("option:selected").text();
				}else{
					return ptxt+" "+cselect.find("option:selected").text()+" "+dselect.find("option:selected").text();
				}
			}
		}
	}
}

function getPreAddress(){
	var pselect=jQ("#preaddressdiv select").eq(0);
	var cselect=jQ("#preaddressdiv select").eq(1);
	var dselect=jQ("#preaddressdiv select").eq(2);
	var pval=eval(pselect.val());
	if(pval==0){
		return "0";
	}else{
		var ptype=eval(pselect.find("option:selected").attr("type"));
		if(ptype==-1){
			var cval="0";
			var dval=eval(dselect.val());
			if(dval==0){
				return ""+pval;
			}else{
				return pval+"_0_"+dval;
			}
		}else{
			var cval=eval(cselect.val());
			if(cval==0){
				return ""+pval;
			}else{
				var dval=eval(dselect.val());
				if(dval==0){
					return pval+"_"+cval;
				}else{
					return pval+"_"+cval+"_"+dval;
				}
			}
		}
	}
}

function loadUserInfo(){
	loadUserEmail();
	jQ.ajax({
		type:"POST",
		url:"controlAjax!userInfo.action",
		success:function(data){
			if(data.result){
				var email=data.email;
				var name=data.name;
				var address=data.address;
				var sufaddress=data.sufaddress;
				var addresscode=data.addresscode;
				var birth=data.birth;
				var birthlong=data.birthlong;
				var qq=data.qq;
				var msn=data.msn;
				var blog=data.blog;
				var sex=data.sex;
				var mobilenum=data.mobilenum;
				var mobileisbindable=data.mobileisbindable;
				
				var issina=data.issina;
				var isouter=data.isouter;
				if(issina){
					jQ("#userinfo_email").empty().append("新浪微博登录");
				}else{
					jQ("#userinfo_email").empty().append(email);
				}
				jQ("#userinfo_name").data("name",name);
				jQ("#userinfo_name").empty().append(name);
				jQ("#userinfo_sex").data("sex",sex);
				jQ("#userinfo_sex").empty().append(sex==1?"男":"女");
				jQ("#userinfo_birth").data("birth",birth);
				jQ("#userinfo_birth").data("birthlong",birthlong);
				jQ("#userinfo_birth").empty().append(birth);
				jQ("#userinfo_qq").data("qq",qq);
				jQ("#userinfo_qq").empty().append(qq);
				jQ("#userinfo_msn").data("msn",msn);
				jQ("#userinfo_msn").empty().append(msn);
				jQ("#userinfo_blog").data("blog",blog);
				jQ("#userinfo_blog").empty().append(blog);
				jQ("#userinfo_living").empty().append(address);
				jQ("#userinfo_living").data("sufaddress",sufaddress);
				jQ("#userinfo_living").data("address",address);
				jQ("#userinfo_living").data("addresscode",addresscode);
				if(mobilenum.length>0){
					jQ("#userinfo_mobile").data("mobilenum",mobilenum);
					jQ("#userinfo_mobile").data("mobileisbindable",mobileisbindable);
					var mobileisbindablestr=eval(mobileisbindable)?"":" 未验证";
					jQ("#userinfo_mobile").empty();
					jQ("#userinfo_mobile").append(mobilenum+mobileisbindablestr);
				}else{
					jQ("#userinfo_mobile").data("mobilenum","");
					jQ("#userinfo_mobile").empty().append("未绑定");
				}
				jQ("#userinfo_isouter").find("label").nextAll().remove();
				if(isouter){
					var tmphtml="";
					tmphtml+="<div class=\"dostatus\">";
					tmphtml+="<span class=\"snsvalbox\">绑定账号：</span>";
					tmphtml+="<span class=\"snsinfo\">新浪微博</span>";
					tmphtml+="<i class=\"sinalogo\"></i>";
					tmphtml+="</div>";
					if(!issina){
						tmphtml+="<a class=\"unbindsns\">解除绑定微博账号</a>";
					}
				}else{
					var tmphtml="";
					tmphtml+="<div class=\"undostatus\">";
					tmphtml+="<span class=\"snsvalbox\">您还未绑定社交账号</span>";
					tmphtml+="<a class=\"bindsns\"></a>";
					tmphtml+="</div>";
					
				}
				
				jQ("#userinfo_isouter").find("label").after(tmphtml);
				jQ("#userinfo_isouter div.undostatus").find("a.bindsns").bind("click",bindSinaSNS);
				jQ("#userinfo_isouter").find("a.unbindsns").bind("click",unbindSinaSNS);
				jQ("#mobileupdate").bind("click",showMobileupdateinf);
			}else{
				clip_tips(data.errormsg);
				window.location.href=jQ("#ctxVal").val()+"/index.html";
			}
		}
	});
}
var mobilever = new RegExp(/((1(30|31|32|33|34|35|36|37|38|39|45|47|50|51|52|53|54|55|56|57|58|59|80|81|82|83|84|85|86|87|88|89)\d{8,8})|((106|0)\d{10,11}))/img);
var mobilecode=new RegExp(/(\d{6})/img);
function showMobileupdateinf(){
	jQ("#mobileupdate").hide();
	var mobilenum=jQ("#userinfo_mobile").data("mobilenum");
	if(mobilenum.length>0){
		jQ("#userinfo_mobile").empty().append("<input type='text' value='"+mobilenum+"'>");
	}else{
		jQ("#userinfo_mobile").empty().append("<input type='text' >");
	}
	jQ("#userinfo_mobile").append("<a class='sendcode'>");
	var pdiv=jQ("#userinfo_mobile").parent();
	pdiv.after("<div><label>验证码：</label><input type='text' id='vcode' maxlength=6><a class='confirmcode'></div><div><a class='close' id='mobileupdateclose'>关闭修改</a></div>");
	jQ("#userinfo_mobile").find("a.sendcode").bind("click",sendVerCode);
	jQ("#mobileupdateclose").bind("click",closeMobileupdateinf);
	
}

function closeMobileupdateinf(){
	var mobilenum=jQ("#userinfo_mobile").data("mobilenum");
	var mobileisbindable=eval(jQ("#userinfo_mobile").data("mobileisbindable"));
	jQ("#userinfo_mobile").nextAll("span").remove();
	jQ("#userinfo_mobile").parent().nextAll("div").remove();
	if(mobilenum.length>0){
		var mobileisbindablestr=eval(mobileisbindable)?"":" 未验证";
		jQ("#userinfo_mobile").empty();
		jQ("#userinfo_mobile").append(mobilenum+mobileisbindablestr);
	}else{
		jQ("#userinfo_mobile").empty().append("未绑定");
	}
	jQ("#mobileupdate").show();
}

function sendVerCode(){
	jQ("#userinfo_mobile").find("a.sendcode").unbind("click");
	
	jQ("#userinfo_mobile").find("a.sendcode").unbind("click");
	var mobilenum=jQ("#userinfo_mobile").data("mobilenum",mobilenum);
	var mobileval=jQ.trim(jQ("#userinfo_mobile").find("input").val());
	jQ("#userinfo_mobile").find("input").data("mobilenum",mobileval);
	var mobileisbindable=eval(jQ("#userinfo_mobile").data("mobileisbindable"));
	if(mobileval.length<=0){
		jQ("#userinfo_mobile").nextAll("span").remove();
		jQ("#userinfo_mobile").after("<span class='error'>请输入手机号码</span>");
		jQ("#userinfo_mobile").find("a.sendcode").bind("click",sendVerCode);
		return;
	}
	if(mobileval==mobilenum&&mobileisbindable==1){
		jQ("#userinfo_mobile").nextAll("span").remove();
		jQ("#userinfo_mobile").after("<span class='error'>该手机号码已经绑定</span>");
		jQ("#userinfo_mobile").find("a.sendcode").bind("click",sendVerCode);
		return;
	}
	if(!mobileval.match(mobilever)){
		jQ("#userinfo_mobile").nextAll("span").remove();
		jQ("#userinfo_mobile").after("<span class='error'>请输入正确的手机号码</span>");
		jQ("#userinfo_mobile").find("a.sendcode").bind("click",sendVerCode);
		return;
	}
	jQ.ajax({
		type:"POST",
		url:"userAjax!sendVerCodeAndReset.action",
		data:{
			mobilenum:mobileval
		},
		success:function(data){
			var dataObj=eval("("+data+")");
			if(dataObj.flag){
				jQ("#userinfo_mobile").nextAll("span").remove();
				jQ("#userinfo_mobile").after("<span class='right'>发送成功，<i id='countdown'>60</i>秒后可再次点击”发送验证“。</span>");
				jQ("#userinfo_mobile").find("a.sendcode").bind("click",cant_sendVerCode);
				jQ("#countdown").data("num",60);
				jQ("#vcode").next("a.confirmcode").bind("click",verCode);
				startCooldown();
			}else{
				jQ("#userinfo_mobile").find("a.sendcode").bind("click",sendVerCode);
				clip_tips(dataObj.result);
				
			}
		}
	});
}

function cant_sendVerCode(){
	clip_tips("对不起，60秒内请勿多次请求手机验证码。");
}

function startCooldown(){
	var scroll=setInterval(function(){
		var num=eval(jQ("#countdown").data("num"));
		num--;
		if(num<1){
			jQ("#userinfo_mobile").nextAll("span").remove();
			jQ("#userinfo_mobile").find("a.sendcode").unbind("click").bind("click",sendVerCode);
			clearInterval(scroll);
		}else{
			jQ("#countdown").data("num",num);
			jQ("#countdown").text(num);
		}
	},1000);
}

function verCode(){
	jQ("#userinfo_mobile").find("a.sendcode").unbind("click");
	jQ("#vcode").next("a.confirmcode").unbind("click");
	var minput=jQ.trim(jQ("#vcode").val());
	if(!minput.match(mobilecode)){
		jQ("#vcode").next("a.confirmcode").after("<span class='error'>验证码只可能是6个数字。</span>");
		return;
	}else{
		jQ.ajax({
			type:"POST",
			url:"userAjax!verifyCode.action",
			data:{
				codenum:minput
			},
			success:function(data){
				var dataObj=eval("("+data+")");
				if(dataObj.flag){
					clip_tips("验证成功");
					var mobileval=jQ("#userinfo_mobile").find("input").data("mobilenum");
					jQ("#userinfo_mobile").data("mobilenum",mobileval);
					jQ("#userinfo_mobile").data("mobileisbindable",1);
					jQ("#userinfo_mobile").empty();
					jQ("#userinfo_mobile").nextAll("span").remove();
					jQ("#userinfo_mobile").parent().nextAll("div").remove();
					jQ("#userinfo_mobile").append(mobileval);
					jQ("#mobileupdate").show();
				}else{
					jQ("#userinfo_mobile").find("a.sendcode").bind("click",sendVerCode);
					jQ("#vcode").next("a.confirmcode").bind("click",verCode);
					clip_tips(dataObj.result);
				}
			}
		});
		
	}
}

function bindSinaSNS(){
	var url=window.location.href;
	if(url.indexOf("?")>0){
		url=url.substring(0,url.indexOf("?"));
	}
	jQ.ajax({
		type: "POST",
		url: "userAjax!userCreateSinaOAuth2URL.action",
		data:{
			suffixurl:url
		},
		success:function(data){
			if(data.result){
				window.location.href=data.oauthurl;
			}else{
				alert(data.errormsg);
			}
		}
	});
}



function unbindSinaSNS(){
	jQ.ajax({
		type: "POST",
		url: "userAjax!unbindUserSina.action",
		success:function(data){
			if(data.result){
				var tmphtml="";
				tmphtml+="<div class=\"undostatus\">";
				tmphtml+="<span class=\"snsvalbox\">您还未绑定社交账号</span>";
				tmphtml+="<a class=\"bindsns\"></a>";
				tmphtml+="</div>";
				jQ("#userinfo_isouter").find("label").nextAll().remove();
				jQ("#userinfo_isouter").find("label").after(tmphtml);
				jQ("#userinfo_isouter div.undostatus").find("a.bindsns").bind("click",bindSinaSNS);
			}else{
				clip_tips(data.errormsg);
			}
		}
	});
}

function loadUserEmail(){
	jQ.ajax({
		type:"POST",
		url:"controlAjax!userEmail.action",
		success:function(data){
			if(data!=null){
				var emailhtml="";
				jQ(data).find('email').each(function(){
					var email=jQ(this).find("Email").text();
					var emailId=jQ(this).find("Id").text();
					var Contacttypeid=jQ(this).find("Contacttypeid").text();
					var Bindable=jQ(this).find("Bindable").text();
					var Status=jQ(this).find("Status").text();
					emailhtml+="<fieldset class=\"add_mail pp\" id='email_"+emailId+"'>";
					if(eval(Contacttypeid)==0){
						emailhtml+="<legend>注册邮箱</legend>";
					}else{
						if(eval(Bindable)==1){
							emailhtml+="<legend>绑定邮箱</legend>";
						}else{
							emailhtml+="<legend>未验证邮箱</legend>";
						}
					}
					emailhtml+="<ul emailid="+emailId+">";
					emailhtml+="<li  class='email'>";
					emailhtml+="<label>邮箱：</label>";
					emailhtml+="<span class=\"emailval\">"+email+"</span>";
					emailhtml+="</li>";
					if(eval(Bindable)==1){
						emailhtml+="<li status='"+Status+"'>";
						if(eval(Status)==1)
							emailhtml+="<input type=\"checkbox\" checked=\"checked\" disabled='disabled'>";
						else
							emailhtml+="<input type=\"checkbox\" disabled='disabled'>";
						emailhtml+="<span>是否设置为接收邮箱</span>";
						emailhtml+="</li>";
					}else{
						emailhtml+="<li>";
						emailhtml+="<span class='info'>邮箱地址需要验证</span>";
						emailhtml+="</li>";
					}
					emailhtml+="<li><a onclick=\"deleteEmail(this)\">删除</a>";
					if(eval(Bindable)==1){
						emailhtml+="<a onclick=\"editEmail(this)\">编辑</a>";
					}else{
						emailhtml+="<a onclick=\"resendEmail(this)\">再次发送</a>";
					}
					emailhtml+="</li>";
					emailhtml+="</ul>";
					emailhtml+="</fieldset>";
				});
				emailhtml+="<fieldset class=\"add_mail pp\">";
				emailhtml+="<legend>添加新邮箱</legend>";
				emailhtml+="<ul>";
				emailhtml+="<li class='email'>";
				emailhtml+="<label>邮箱：</label>";
				emailhtml+="<span class=\"emailval\"><input type='text' class='txt'></span>";
				emailhtml+="</li>";
				emailhtml+="<li>";
				emailhtml+="<span class='err'></span>";
		        emailhtml+="</li>";
				emailhtml+="<li>";
				emailhtml+="<a class='addemail' onclick='addEmail(this);'>添加</a>";
		        emailhtml+="</li>";
		        emailhtml+="</ul>";
		        emailhtml+="</fieldset>";
				jQ("#emailinfo_title").nextAll().remove();
		        jQ("#emailinfo_title").after(emailhtml);
					
			}
		}
	});
}

function deleteEmail(obj){
	var liobj=jQ(obj).parent();
	var ulobj=liobj.parent();
	jalert("确认要删除这个邮箱吗？",{emailid:ulobj.attr("emailid")},confirmDeleteEmail);
}

function confirmDeleteEmail(event){
	var emailid=event.data.emailid;
	jQ.ajax({
		type:"POST",
		url:"controlAjax!deleteEmail.action",
		data:{
			emailid:emailid
		},
		success:function(data){
			if(data.result){
				jQ("#email_"+emailid).remove();
			}
		}
	});
}

function editEmail(obj){
	var liobj=jQ(obj).parent();
	liobj.empty().append("<a onclick='cancelEdit(this);'>取消</a><a onclick='okEdit(this);'>确定</a>");
	var inputliobj=liobj.prev();
	inputliobj.find("input").attr("disabled",false);
}

function okEdit(obj){
	var liobj=jQ(obj).parent();
	var prevliobj=liobj.prev();
	var mailstatus=eval(prevliobj.attr("status"));
	var inputobj=prevliobj.find("input");
	var checkedval=inputobj.attr("checked")?1:0;
	if(mailstatus==checkedval){
		if(eval(mailstatus)==1)
			inputobj.attr("checked",true);
		else
			inputobj.attr("checked",false);
		inputobj.attr("disabled","disabled");
		liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"editEmail(this)\">编辑</a>");
	}else{
		var ulobj=liobj.parent();
		var emailid=ulobj.attr("emailid");
		jQ.ajax({
			type:"POST",
			url:"controlAjax!updateUserEmail.action",
			data:{
				emailid:emailid,
				emailaccept:checkedval
			},
			success:function(data){
				if(data.result){
					prevliobj.attr("status",checkedval);
					if(eval(checkedval)==1)
						inputobj.attr("checked",true);
					else
						inputobj.attr("checked",false);
					inputobj.attr("disabled","disabled");
					liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"editEmail(this)\">编辑</a>");
				}else{
					clip_tips(data.errormsg);
				}
			}
		});
	}
}

function cancelEdit(obj){
	var liobj=jQ(obj).parent();
	var prevliobj=liobj.prev();
	var mailstatus=prevliobj.attr("status");
	var inputobj=prevliobj.find("input");
	if(eval(mailstatus)==1)
		inputobj.attr("checked",true);
	else
		inputobj.attr("checked",false);
	inputobj.attr("disabled","disabled");
	liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"editEmail(this)\">编辑</a>");
}

function resendEmail(obj){
	var liobj=jQ(obj).parent();
	var readystatus=liobj.prev().find("span.ready").length;
	var spanobj=liobj.prevAll("li.email").find("span.emailval");
	var email=spanobj.text();
	if(readystatus){
		clip_tips("对不起，60秒内请勿多次请求验证该邮箱地址。");
		return;
	}
	var ulobj=liobj.parent();
	var emailid=ulobj.attr("emailid");
	jQ.ajax({
		type:"POST",
		url:"controlAjax!resendEmail.action",
		data:{
			emailid:eval(emailid)
		},
		success:function(data){
			if(data.result){
				var infoline=liobj.prev();
				infoline.empty().append("<span class='ready'>已发送验证邮件，在<i class='countdown'>60</i>秒后，方可再次验证。</span>");
				infoline.find("i.countdown").data("num",60);
				var scroll=setInterval(function(){
					var num=eval(infoline.find("i.countdown").data("num"));
					num--;
					if(num<1){
						infoline.empty().append("<span class='info'>邮箱地址需要验证</span>");
						clearInterval(scroll);
					}else{
						infoline.find("i.countdown").data("num",num);
						infoline.find("i.countdown").text(num);
					}
				},1000);
			}else{
				clip_tips(data.errormsg);
			}
			
		}
	});
}

function addEmail(obj){
	var liobj=jQ(obj).parent();
	var errorzone=liobj.prev().find("span.err");
	var spanobj=liobj.prevAll("li.email").find("span.emailval");
	var inputobj=spanobj.find("input");
	var emailval=inputobj.val();
	if(emailval.length<=0){
		errorzone.empty().append("请输入邮箱地址");
		return;
	}else if(!isEmail(emailval)){
		errorzone.empty().append("请输入正确的邮箱地址");
		return;
	}else{
		jQ.ajax({
			type:"POST",
			url:"controlAjax!saveEmail.action",
			data:{
				emailInput:emailval
			},
			success:function(data){
				if(data.result){
					var emailid=data.emailid;
					var ulobj=liobj.parent();
					ulobj.attr("emailid",emailid);
					var fieldsetobj=ulobj.parent();
					fieldsetobj.attr("id","email_"+emailid);
					var titleobj=fieldsetobj.find("legend");
					titleobj.text("未验证邮箱");
					spanobj.empty().append(emailval);
					var errorline=errorzone.parent();
					errorzone.remove();
					errorline.append("<span class='ready'>已发送验证邮件，在<i class='countdown'>60</i>秒后，方可再次验证。</span>");
					liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"resendEmail(this)\">发送验证</a>");
					errorline.find("i.countdown").data("num",60);
					var scroll=setInterval(function(){
						var num=eval(errorline.find("i.countdown").data("num"));
						num--;
						if(num<1){
							errorline.empty().append("<span class='info'>邮箱地址需要验证</span>");
							clearInterval(scroll);
						}else{
							errorline.find("i.countdown").data("num",num);
							errorline.find("i.countdown").text(num);
						}
					},1000);
					var emailhtml="";
					emailhtml+="<fieldset class=\"add_mail pp\">";
					emailhtml+="<legend>添加新邮箱</legend>";
					emailhtml+="<ul>";
					emailhtml+="<li class='email'>";
					emailhtml+="<label>邮箱：</label>";
					emailhtml+="<span class=\"emailval\"><input type='text' class='txt'></span>";
					emailhtml+="</li>";
					emailhtml+="<li>";
					emailhtml+="<span class='err'></span>";
			        emailhtml+="</li>";
					emailhtml+="<li>";
					emailhtml+="<a class='addemail' onclick='addEmail(this);'>添加</a>";
			        emailhtml+="</li>";
			        emailhtml+="</ul>";
			        emailhtml+="</fieldset>";
			        jQ("#emailinfo_title fieldset:last").after(emailhtml);
//					clip_tips(dataObj['result']);
				}else{
					clip_tips(data.errormsg);
				}
			}
		});
	}
	
	
}

function formateBirthTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy-MM-dd");
}


